<template>
	<view class="content">
		<view class="btn-row">
			<div v-if="!hasLogin">
				<button type="primary" class="primary" @tap="bindLogin">登录</button>
			</div>
			<div  v-if="hasLogin">
				<button v-if="hasLogin" type="default" @tap="bindLogout">退出登录</button>
			</div>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'

	export default {
		data(){
			return{
				hasLogin: false,
			}
		},
		onShow(){
			this.judgeLogin();
		},
		methods: {
			judgeLogin(){
				this.hasLogin = localStorage.getItem("hasLogin");
			},
			bindLogin() {
				this.$router.push('../login/login')
			},
			bindLogout() {
				this.$store.commit('logoff');
				this.$router.replace('../main/main');
				this.$message.success("退出登录成功");
				/**
				 * 如果需要强制登录跳转回登录页面
				 */
				// if (this.forcedLogin) {
				// 	this.$router.push('../login/login')
				// }
			},
		}
	}
</script>

<style>

</style>
